<template>
  <div class="login_container">
    <div class="login_box">
      <!-- 头像区 -->
      <div class="avatar_box">
        <img src="../assets/img/logo.png" alt="" />
      </div>
      <!-- 登录表单区 -->
      <el-form
        label-width="0px"
        class="demo-ruleForm"
        :model="loginForm"
        :rules="loginRules"
        ref="ruleLoginForm"
      >
        <!-- 用户名 -->
        <el-form-item prop="username">
          <el-input
            prefix-icon="el-icon-user-solid"
            v-model="loginForm.uesrname"
          ></el-input>
        </el-form-item>
        <!-- 密码 -->
        <el-form-item prop="password">
          <el-input
            prefix-icon="el-icon-goods"
            v-model="loginForm.password"
            type="password"
          ></el-input>
          <!-- 按钮区域 -->
        </el-form-item>
        <el-form-item class="bnts">
          <el-button type="primary" @click="Login">登录</el-button>
          <el-button type="info" @click="ressetLogin">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      loginForm: {
        uesrname: "az",
        password: "123",
      },
      loginRules: {
        username: [
          { required: true, message: "请输入登录名称", trigger: "blur" },
          {
            min: 3,
            max: 10,
            message: "长度在 3 到 10 个字符",
            trigger: "blur",
          },
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          {
            min: 3,
            max: 10,
            message: "长度在 3 到 10 个字符",
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    ressetLogin() {
      this.$refs.ruleLoginForm.resetFields();
    },
    Login() {
      this.$refs.ruleLoginForm.validate((valid) => {
        // console.log(valid)
        this.$message.error({
          message: "错误的",
          duration: 2000,
        });
        // 如果登录成功的话 将token存储到sessionstrog中
        window.sessionStorage.setItem("token", "后台的token");
        // 登录成功后然后跳转到首页
        this.$router.push("/home");
      });
    },
  },
};
</script>
<style scoped>
.login_container {
  background-color: #283f57ad;
  height: 100%;
  /* position: relative; */
}
.login_box {
  width: 400px;
  height: 300px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  border-radius: 3px;
  background-color: #fff;
  position: relative;
}
.avatar_box {
  width: 130px;
  height: 130px;
  border-radius: 50%;
  padding: 10px;
  border: 1px solid rgba(204, 204, 204, 0.342);
  box-shadow: 0 0 10px #ccc;
  position: absolute;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: #fff;
}
.avatar_box img {
  width: 100%;
  border-radius: 50%;
  background-color: rgba(204, 204, 204, 0.445);
}
.bnts {
  display: flex;
  justify-content: flex-end;
}
.demo-ruleForm {
  position: absolute;
  bottom: 0;
  width: 100%;
  padding: 0 20px;
  box-sizing: border-box;
}
</style>
